<template>
  <el-card style="margin-bottom:20px;">
    <div slot="header" class="clearfix">
      <span>个人信息</span>
    </div>

    <div class="user-profile">
      <div class="box-center">
        <pan-thumb
          :image="user.avatar"
          :height="'100px'"
          :width="'100px'"
          :hoverable="false"
        >
          <div>Hello</div>
          {{ user.username }}
        </pan-thumb>
      </div>
      <div class="box-center">
        <div class="user-name text-center">
          {{ user.name }}
        </div>
        <div class="user-role text-center text-muted">
          <span>{{ user.email }}</span>

          <span class="edit-profile">
            <el-tooltip
              class="item"
              effect="dark"
              content="修改邮箱"
              placement="bottom"
            >
              <svg-icon name="edit" @click="edit('email')" />
            </el-tooltip>
          </span>
        </div>
      </div>
    </div>

    <div class="user-bio">
      <div class="user-profile user-bio-section">
        <div class="user-bio-section-header">
          <span> <svg-icon name="education" /><span>基本信息</span></span>
          <span class="edit-profile">
            <el-tooltip
              class="item"
              effect="dark"
              content="修改基本信息"
              placement="bottom"
            >
              <svg-icon name="edit" @click="edit('baseInfo')" />
            </el-tooltip>
          </span>
        </div>
        <div class="user-bio-section-body">
          <div class="text-muted" style="font-weight: 600; margin-bottom:20px;">
            {{ user.mobile ? '电话号码：' + user.mobile : '' }}
          </div>
          <div class="text-muted">
            {{ user.remark }}
          </div>
        </div>
      </div>

      <div class="user-skills user-bio-section">
        <div class="user-bio-section-header">
          <span> <svg-icon name="bug" /><span>激活状态</span></span>
        </div>
        <div class="user-bio-section-body">
          <div class="text-muted">
            <el-tag
              :disable-transitions="true"
              :type="user.status | userStatusBgFilter"
            >
              {{ user.status | userStatusFilter }}
            </el-tag>
          </div>
        </div>
      </div>

      <div class="user-password user-bio-section">
        <div class="user-bio-section-header">
          <span> <svg-icon name="password" /><span>修改密码</span></span>
          <span class="edit-profile">
            <el-tooltip
              class="item"
              effect="dark"
              content="修改密码"
              placement="bottom"
            >
              <svg-icon name="edit" @click="edit('password')" />
            </el-tooltip>
          </span>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
import { IProfile } from '../index.vue'
import PanThumb from '@/components/PanThumb/index.vue'

@Component({
  name: 'UserCard',
  components: {
    PanThumb
  }
})
export default class extends Vue {
  @Prop({ required: true }) private user!: IProfile
  private edit(str: string) {
    this.$emit('editProfile', str)
  }
}
</script>

<style lang="scss" scoped>
.box-center {
  margin: 0 auto;
  display: table;
}

.text-muted {
  color: #777;
}

.user-profile {
  &:hover {
    .edit-profile {
      visibility: visible;
    }
  }
  .edit-profile {
    padding-left: 5px;
    visibility: hidden;
    cursor: pointer;
  }
  .user-name {
    font-weight: bold;
  }

  .box-center {
    padding-top: 10px;
  }

  .user-role {
    padding-top: 10px;
    font-weight: 400;
    font-size: 14px;
  }

  .box-social {
    padding-top: 30px;

    .el-table {
      border-top: 1px solid #dfe6ec;
    }
  }

  .user-follow {
    padding-top: 20px;
  }
}

.user-bio {
  margin-top: 20px;
  color: #606266;
  .user-profile {
    &:hover {
      .edit-profile {
        visibility: visible;
      }
    }
    .edit-profile {
      visibility: hidden;
      cursor: pointer;
    }
  }
  .user-password {
    &:hover {
      .edit-profile {
        visibility: visible;
      }
    }
    .edit-profile {
      visibility: hidden;
      cursor: pointer;
    }
  }
  span {
    padding-left: 4px;
  }

  .user-bio-section {
    font-size: 14px;
    padding: 15px 0;

    .user-bio-section-header {
      border-bottom: 1px solid #dfe6ec;
      padding-bottom: 10px;
      margin-bottom: 10px;
      font-weight: bold;
      display: flex;
      justify-content: space-between;
    }
  }
}
</style>
